import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/routes/tab_moments/controller/xindong_dongtai_tab_controller.dart';
import 'package:xindong/routes/tab_moments/publish/xindong_dongtai_publish_yemian.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/common/xindong_tab_indicator.dart';
import 'package:xindong/widgets/container/xindong_home_container.dart';

class XinDongDongTaiYeMian extends StatefulWidget {
  const XinDongDongTaiYeMian({super.key});

  @override
  State<XinDongDongTaiYeMian> createState() => _XinDongDongTaiYeMianState();
}

class _XinDongDongTaiYeMianState extends State<XinDongDongTaiYeMian>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  final _tabController = Get.put(XinDongDongTaiTabController());

  @override
  void initState() {
    super.initState();

    // Tab控制器
    _tabController.initWithVsync(this);
  }

  // 避免状态重置
  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return XinDongHomeBackgroundView(
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: XinDongAppBar(
          "",
          leading: const SizedBox(),
          leadingWidth: 0.0,
          elevation: 0.0,
          backgroundColor: Colors.transparent,
          titleView: Container(
            alignment: Alignment.centerLeft,
            child: TabBar(
              isScrollable: true,
              indicator: const XinDongTabIndicator(color: DZColors.mainColor),
              indicatorSize: TabBarIndicatorSize.label,
              labelPadding: const EdgeInsets.only(left: 16, right: 5),
              labelColor: DZColors.titleColor,
              unselectedLabelColor: DZColors.placeholderColor,
              labelStyle: const TextStyle(fontSize: kTitleFontSize, fontWeight: FontWeight.w500),
              unselectedLabelStyle: const TextStyle(fontSize: 16),
              tabs: _tabController.tabBar(),
              controller: _tabController.tabController,
            ),
          ),
        ),
        body: TabBarView(
          controller: _tabController.tabController,
          children: _tabController.tabBarViews(),
        ), // 悬浮发布按钮
        floatingActionButton: FloatingActionButton(
          onPressed: () => XinDongPageSingleton.instance.pushYeMian(const XinDongDongTaiPublishYeMian()),
          backgroundColor: Colors.transparent,
          splashColor: Colors.transparent,
          tooltip: "发布动态",
          child: ImageUtil.asset(AssetsRes.BUTTON_DYNAMIC_ISSUE, height: 50, width: 50),
        ),
      ),
    );
  }
}
